import 'package:flutter/material.dart';
import 'package:flutter_study/DrawerDemo.dart';
import 'package:flutter_study/TabBarDemo.dart';
import 'package:flutter_study/widget/InputDemo.dart';
import 'package:flutter_study/widget/ProgressDemo.dart';

///底部选项卡
///bottomNavigationBar的两种牛逼实现方式
///1.BottomNavigationBar
///2.BottomAppBar
class BottomNavigatorDemo extends StatefulWidget {
  // const BottomNavigatorDemo({Key? key}) : super(key: key);

  List<Widget> _widgetList = [
    ProgressDemo(),
    TabBarDemo(),
  ];

  @override
  _BottomNavigatorDemoState createState() => _BottomNavigatorDemoState();
}

class _BottomNavigatorDemoState extends State<BottomNavigatorDemo> {
  int _index = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text("底部选项卡"),
      ),

      ///1.
      // bottomNavigationBar: BottomNavigationBar(
      ///type属性是必须指定的
      //   type: BottomNavigationBarType.fixed,
      //   currentIndex: _index,
      //   onTap: (v) {
      //     setState(() {
      //       _index = v;
      //     });
      //   },
      //   items: [
      //     BottomNavigationBarItem(icon: Icon(Icons.add), label: "新增"),
      //     BottomNavigationBarItem(icon: Icon(Icons.home), label: "home"),
      //   ],
      // ),
      ///2.
      bottomNavigationBar: BottomAppBar(
        shape: CircularNotchedRectangle(),
        color: Theme.of(context).primaryColor,
        child: Row(
          //三个组件平分宽高
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            IconButton(onPressed: () {
              setState(() {
                _index = 0;
              });
            }, icon: Icon(Icons.add)),
            SizedBox(),
            IconButton(onPressed: () {
              setState(() {
                _index = 1;
              });
            }, icon: Icon(Icons.home)),
          ],
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          print("hh");
        },
        child: Icon(Icons.widgets_rounded),
      ),
      body: widget._widgetList[_index],
    );
  }
}
